package com.system.business.controller;

import com.system.business.been.Business;
import com.system.business.been.IntervalPlanLst;
import com.system.business.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author 林
 */
@RestController
@RequestMapping("/business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @PostMapping("/save")
    public boolean saveHandle(@RequestBody Business business){
        return businessService.saveBusiness(business);
    }

    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id){
        return businessService.removeBusinessById(id);
    }

    @PutMapping("/update")
    public boolean updateHandle(@RequestBody Business business){
        return businessService.modifyBusiness(business);
    }

    @GetMapping("/get/{id}")
    public Business getHandle(@PathVariable("id") int id){
        return businessService.getBusinessById(id);
    }

    @GetMapping("/get/list")
    public List<Business> listHandle(){
        return businessService.listAllBusinesses();
    }
    @GetMapping("/get/findByBusinessId/{businessId}")
    public Integer findByBusinessId(@PathVariable("businessId") int businessId){
        return businessService.findByBusinessId(businessId);
    }

    @GetMapping("/get/findAllIntervalPlanLstByBusinessId/{businessId}")
    public List<IntervalPlanLst> findAllIntervalPlanLstByBusinessId(@PathVariable("businessId") int businessId){
        return businessService.findAllIntervalPlanLstByBusinessId(businessId);
    }

    @GetMapping("/get/findAllByDepartmentId/{businessId}")
    public List<Business> findAllByDepartmentId(@PathVariable("businessId") int businessId){
        return businessService.findAllByDepartmentId(businessId);
    }
}
